package com.ruoyi.buss.task.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.buss.task.domain.DataUserTaskRelation;
import com.ruoyi.buss.task.service.IDataUserTaskRelationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 营销任务和客户关系Controller
 * 
 * @author sxy
 * @date 2021-07-16
 */
@RestController
@RequestMapping("/taskUserRelation")
public class DataUserTaskRelationController extends BaseController
{
    @Autowired
    private IDataUserTaskRelationService dataUserTaskRelationService;

    /**
     * 查询营销任务和客户关系列表
     */
    @PreAuthorize(hasPermi = "buss:taskUserRelation:list")
    @GetMapping("/list")
    public TableDataInfo list(DataUserTaskRelation dataUserTaskRelation)
    {
        startPage();
        List<DataUserTaskRelation> list = dataUserTaskRelationService.selectDataUserTaskRelationList(dataUserTaskRelation);
        return getDataTable(list);
    }

    /**
     * 导出营销任务和客户关系列表
     */
    @PreAuthorize(hasPermi = "buss:taskUserRelation:export")
    @Log(title = "营销任务和客户关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataUserTaskRelation dataUserTaskRelation) throws IOException
    {
        List<DataUserTaskRelation> list = dataUserTaskRelationService.selectDataUserTaskRelationList(dataUserTaskRelation);
        ExcelUtil<DataUserTaskRelation> util = new ExcelUtil<DataUserTaskRelation>(DataUserTaskRelation.class);
        util.exportExcel(response, list, "营销任务和客户关系数据");
    }

    /**
     * 获取营销任务和客户关系详细信息
     */
    @PreAuthorize(hasPermi = "buss:taskUserRelation:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(dataUserTaskRelationService.selectDataUserTaskRelationById(id));
    }

    /**
     * 新增营销任务和客户关系
     */
    @PreAuthorize(hasPermi = "buss:taskUserRelation:add")
    @Log(title = "营销任务和客户关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataUserTaskRelation dataUserTaskRelation)
    {
        return toAjax(dataUserTaskRelationService.insertDataUserTaskRelation(dataUserTaskRelation));
    }

    /**
     * 修改营销任务和客户关系
     */
    @PreAuthorize(hasPermi = "buss:taskUserRelation:edit")
    @Log(title = "营销任务和客户关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataUserTaskRelation dataUserTaskRelation)
    {
        return toAjax(dataUserTaskRelationService.updateDataUserTaskRelation(dataUserTaskRelation));
    }

    /**
     * 删除营销任务和客户关系
     */
    @PreAuthorize(hasPermi = "buss:taskUserRelation:remove")
    @Log(title = "营销任务和客户关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dataUserTaskRelationService.deleteDataUserTaskRelationByIds(ids));
    }
}
